<?php
include_once('./common.php');
$gd = empty($_GET['gd'])? "gd" : $_GET['gd'];
$tid = empty($_GET['tid'])? 0 : $_GET['tid'];
$cid = empty($_GET['cid'])? 0 : $_GET['cid'];
//登录判断
if(empty($_SGLOBAL['supe_uid'])) {
	showmessage('to_login', 'do.php?ac='.$_SCONFIG['login_action']);
}
//站点关闭
checkclose();

if($gd == "gd"){
	include_once('./source/function_common.php');
	$page = empty($_GET['page'])? 1 : intval($_GET['page']);
	if($page < 1){
		$page=1;
	}
	$perpage = 10; //每页要显示的条数
	$start = ($page-1)*$perpage;
	ckstart($start, $perpage);
	$count = $_SGLOBAL['db']->result($_SGLOBAL['db']->query("SELECT COUNT(*) FROM ".tname('contribute')." WHERE checks > 0 AND typeid =".$tid),0);
	$multi = multi($count, $perpage, $page, "grade_c.php");

	$query = $_SGLOBAL['db']->query("SELECT c.*,t.* FROM ".tname('contribute')." AS c LEFT JOIN ".tname('contribute_type')." AS t ON c.typeid = t.tid WHERE c.checks > 0 AND c.typeid =".$tid." ORDER BY c.ontime DESC LIMIT ".$start.",".$perpage);
	while($value = $_SGLOBAL['db']->fetch_array($query)){
		$grade[] = $value;
	}
	include template("grade_c");
}elseif($gd == "grade"){
	if(empty($cid)){
		showmessage('contribute_no_cid', 'grade_c.php');
	}
	$query = $_SGLOBAL['db']->query("SELECT c.*,t.type,f.picid,f.filename,f.fileext FROM ".tname('contribute')." AS c LEFT JOIN ".tname('contribute_type')." AS t ON c.typeid = t.tid LEFT JOIN ".tname('files')." AS f ON c.file = f.filepath WHERE c.cid =".$cid);
	$grade_look = $_SGLOBAL['db']->fetch_array($query);
	include template("grade");
}elseif($gd == "gdsave"){
	$integral = intval($_POST['integral']);
	$cid = intval($_POST['cid']);
	$tid = intval($_POST['tid']);
	updatetable('contribute', array('integral'=>$integral), array('cid'=>$cid));
	showmessage('grade_success', 'grade_c.php?tid='.$tid);
}
?>